<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>Aria: dataLoggerExample.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aria
   &#160;<span id="projectnumber">2.9.4</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('dataLoggerExample_8cpp-example.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">dataLoggerExample.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Show how to register data values with the <a class="el" href="classArDataLogger.html" title="This class will log data, but you have to use it through an ArConfig right now. ">ArDataLogger</a> object. The <a class="el" href="classArDataLogger.html" title="This class will log data, but you have to use it through an ArConfig right now. ">ArDataLogger</a> will obtain a new set of values from functions or pointers you provide (with the return or variable type specified via template parameter) at a regular interval, format the value as text, and write it to a CSV, TSV or fixed-with text file row with a timestamp. <a class="el" href="classArDataLogger.html" title="This class will log data, but you have to use it through an ArConfig right now. ">ArDataLogger</a> also contains various built-in robot-related values by default.</p>
<p><a class="el" href="classArDataLogger.html" title="This class will log data, but you have to use it through an ArConfig right now. ">ArDataLogger</a> will always append new data to the log file, rather than rewriting it. If configuration changes or logging is re-enabled after being disabled, a new header row is written to the file.</p>
<p>All logging, and whether to log individual data values, can be enabled or disabled in program configuration (via <a class="el" href="classArConfig.html" title="Stores configuration information which may be read to and from files or other sources. ">ArConfig</a>), and the file name, file type, and interval can be configured. When used in an ArNetworking server, users can use a client such as MobileEyes to modify this configuration. This example program will use a configuration file called dataLoggerExample.cfg if present. If not present, a new config file with defaults will be created. Edit this file to enable logging and enable individual values to log, and re-run the program.</p>
<p>An ArNetworkingServer can also register these same values with the StringInfo feature for display in MobileEyes or other clients. Configuration can also be changed by users via ArNetworking, and some extra commands can be added such as clearing or saving a copy of the data log. See the ArNetworking examples (and ARNL or MOGS examples, if you have ARNL or MOGS). See the detailed documentation of the <a class="el" href="classArDataLogger.html" title="This class will log data, but you have to use it through an ArConfig right now. ">ArDataLogger</a> class in the ARIA API reference documenttation for more details including which data types are supported.</p>
<div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;Aria.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ariaUtil.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;ArDataLogger.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">/* An example function that returns an int */</span></div><div class="line"><span class="keywordtype">int</span> i = 0;</div><div class="line"><span class="keywordtype">int</span> getExampleInt() { </div><div class="line">  <span class="keywordflow">if</span>(i &gt;= 99999) i = 0;</div><div class="line">  <span class="keywordflow">return</span> i++;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/* An example function that returns a float */</span></div><div class="line"><span class="keywordtype">float</span> f = 2;</div><div class="line"><span class="keywordtype">float</span> getExampleFloat() {</div><div class="line">  <span class="keywordflow">if</span>(f &gt; 99999) f = 0;</div><div class="line">  f *= 2;</div><div class="line">  <span class="keywordflow">return</span> f;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/* An example function that returns an ArPose object. */</span></div><div class="line"><a name="_a0"></a><a class="code" href="classArPose.html">ArPose</a> p;</div><div class="line"><a class="code" href="classArPose.html">ArPose</a> getExamplePose() {</div><div class="line">  <span class="keywordflow">return</span> p;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">/* You can get values from object methods as well */</span></div><div class="line"><span class="keyword">class </span>ExampleClass {</div><div class="line"><span class="keyword">public</span>:</div><div class="line">  <span class="keywordtype">long</span> getRandomNumber() {</div><div class="line">    <span class="keywordflow">return</span> <a name="a1"></a><a class="code" href="group__easy.html#ga4ef94ed579aafcf73419b20ecc7a7138">ArMath::randomInRange</a>(0, 100);</div><div class="line">  }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line">  <a name="a2"></a><a class="code" href="classAria.html#ad99c16b5d947229d9f8e1c5b2d4cdd73">Aria::init</a>();</div><div class="line">  <a name="_a3"></a><a class="code" href="classArArgumentParser.html">ArArgumentParser</a> argparser(&amp;argc, argv);</div><div class="line">  argparser.<a name="a4"></a><a class="code" href="classArArgumentParser.html#a501694b62a7f8b0c3cadd84aeafe1b35">loadDefaultArguments</a>();</div><div class="line">  <a name="_a5"></a><a class="code" href="classArRobot.html">ArRobot</a> robot;</div><div class="line"></div><div class="line">  <a name="_a6"></a><a class="code" href="classArDataLogger.html">ArDataLogger</a> dataLogger(&amp;robot, <span class="stringliteral">&quot;dataLoggerExample.log&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// Make it configurable via config  file or MobileEyes: </span></div><div class="line">  <span class="comment">// To Use config file, you must get ArConfig via</span></div><div class="line">  <span class="comment">// Aria::getConfig() and load the file.  To use a config file and also be</span></div><div class="line">  <span class="comment">// configurable remotely via MobileEyes, also use ArServerHandlerConfig. See</span></div><div class="line">  <span class="comment">// ArNetworking examples and documentation.</span></div><div class="line">  dataLogger.<a name="a7"></a><a class="code" href="classArDataLogger.html#a28f4fc3cf8955e837378502de3707fda">addToConfig</a>(<a name="a8"></a><a class="code" href="classAria.html#ace50b4190f04bcacaf285bb5830c5fc2">Aria::getConfig</a>()); </div><div class="line"></div><div class="line">  dataLogger.<a name="a9"></a><a class="code" href="classArDataLogger.html#a88b932da96a87f73a8c63b977df50bd2">addData</a>&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;Example Int&quot;</span>, <span class="keyword">new</span> <a name="_a10"></a><a class="code" href="classArGlobalRetFunctor.html">ArGlobalRetFunctor&lt;int&gt;</a>(&amp;getExampleInt), <span class="stringliteral">&quot;%d&quot;</span>);</div><div class="line">  dataLogger.<a class="code" href="classArDataLogger.html#a88b932da96a87f73a8c63b977df50bd2">addData</a>&lt;<span class="keywordtype">float</span>&gt;(<span class="stringliteral">&quot;Example Float&quot;</span>, <span class="keyword">new</span> <a name="_a11"></a><a class="code" href="classArGlobalRetFunctor.html">ArGlobalRetFunctor&lt;float&gt;</a>(&amp;getExampleFloat), <span class="stringliteral">&quot;%f&quot;</span>);</div><div class="line">  dataLogger.<a class="code" href="classArDataLogger.html#a88b932da96a87f73a8c63b977df50bd2">addData</a>&lt;<a class="code" href="classArPose.html">ArPose</a>&gt;(<span class="stringliteral">&quot;Example Pose&quot;</span>, <span class="keyword">new</span> <a class="code" href="classArGlobalRetFunctor.html">ArGlobalRetFunctor&lt;ArPose&gt;</a>(&amp;getExamplePose), <span class="stringliteral">&quot;(%f %f %f)&quot;</span>);</div><div class="line">  ExampleClass exampleObj;</div><div class="line">  dataLogger.<a class="code" href="classArDataLogger.html#a88b932da96a87f73a8c63b977df50bd2">addData</a>&lt;<span class="keywordtype">long</span>&gt;(<span class="stringliteral">&quot;Example Random Number&quot;</span>, <span class="keyword">new</span> <a name="_a12"></a><a class="code" href="classArRetFunctorC.html">ArRetFunctorC&lt;long, ExampleClass&gt;</a>(&amp;exampleObj, &amp;ExampleClass::getRandomNumber), <span class="stringliteral">&quot;%ld&quot;</span>);</div><div class="line"></div><div class="line">  <a name="_a13"></a><a class="code" href="classArRobotConnector.html">ArRobotConnector</a> robotConnector(&amp;argparser, &amp;robot);</div><div class="line">  <span class="keywordflow">if</span>(!robotConnector.<a name="a14"></a><a class="code" href="classArRobotConnector.html#ab192ac393d9cc1e5b61b1a82b08d085d">connectRobot</a>())</div><div class="line">  {</div><div class="line">    <a name="a15"></a><a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a16"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;dataLoggerExample: Could not connect to the robot.&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span>(argparser.<a name="a17"></a><a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">    {</div><div class="line">        <span class="comment">// -help not given</span></div><div class="line">        <a name="a18"></a><a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">        <a name="a19"></a><a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (!<a name="a20"></a><a class="code" href="classAria.html#a1b090c01d88bb420b8cf8e0384d25ee1">Aria::parseArgs</a>() || !argparser.<a class="code" href="classArArgumentParser.html#ac3889cbdfa862031c51bf80e06954914">checkHelpAndWarnUnparsed</a>())</div><div class="line">  {</div><div class="line">    <a class="code" href="classAria.html#a10d71f3d4d0cf7f38c58a1f749f64a42">Aria::logOptions</a>();</div><div class="line">    <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(1);</div><div class="line">  }</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a name="a21"></a><a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;dataLoggerExample: Connected to robot.&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="comment">// todo move this into a utility function:</span></div><div class="line">  <a class="code" href="classAria.html#ace50b4190f04bcacaf285bb5830c5fc2">Aria::getConfig</a>()-&gt;<a name="a22"></a><a class="code" href="classArConfig.html#a5f9d30c8911050b8d510837d27f3e067">setBaseDirectory</a>(<span class="stringliteral">&quot;./&quot;</span>);</div><div class="line">  <span class="keywordflow">if</span>(<a class="code" href="classAria.html#ace50b4190f04bcacaf285bb5830c5fc2">Aria::getConfig</a>()-&gt;parseFile(<span class="stringliteral">&quot;dataLoggerExample.cfg&quot;</span>, <span class="keyword">true</span>, <span class="keyword">true</span>))</div><div class="line">  {</div><div class="line">    <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;dataLoggerExample: Loaded config file dataLoggerExample.cfg&quot;</span>);</div><div class="line">  }</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">  {</div><div class="line">    <span class="keywordflow">if</span>(<a name="a23"></a><a class="code" href="classArUtil.html#a731729868fac7cf87c9894fe024f8a6c">ArUtil::findFile</a>(<span class="stringliteral">&quot;dataLoggerExample.cfg&quot;</span>))</div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a012daf6573594f91242f8dd7c02eb74b">ArLog::Terse</a>, <span class="stringliteral">&quot;dataLoggerExample: Warning: Error loading config file dataLoggerExample.cfg.&quot;</span>);</div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">      <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;dataLoggerExample: Creating new config file dataLoggerExample.cfg&quot;</span>);</div><div class="line">      <a class="code" href="classAria.html#ace50b4190f04bcacaf285bb5830c5fc2">Aria::getConfig</a>()-&gt;<a name="a24"></a><a class="code" href="classArConfig.html#af3c8626c844828f2ce632cc7027a7a67">writeFile</a>(<span class="stringliteral">&quot;dataLoggerExample.cfg&quot;</span>);</div><div class="line">    }</div><div class="line">  }</div><div class="line">  </div><div class="line"></div><div class="line">  <span class="comment">// Logging can be enabled/disabled in the configuration.  Or we can always</span></div><div class="line">  <span class="comment">// start logging by calling startLogging:</span></div><div class="line">  dataLogger.<a name="a25"></a>startLogging();</div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;dataLoggerExample: Starting data logging to %s at %d sec interval&quot;</span>, dataLogger.<a name="a26"></a>getLogFileName(), dataLogger.<a name="a27"></a>getLogInterval());</div><div class="line"></div><div class="line">  <span class="comment">// Start the robot processing cycle running in the background.</span></div><div class="line">  <span class="comment">// True parameter means that if the connection is lost, then the </span></div><div class="line">  <span class="comment">// run loop ends.  The robot cycle will trigger dataLogger.</span></div><div class="line">  robot.<a name="a28"></a><a class="code" href="classArRobot.html#a3c1c3056633caf455c8265259f57f6d7">run</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <a class="code" href="classArLog.html#a43a8b3789126c818f390f24bdbceccce">ArLog::log</a>(<a class="code" href="classArLog.html#ac8cc0fb3aa323ab2a1c21340fdd1dce3a7040faf60eeb155eaa85d439b1066ca1">ArLog::Normal</a>, <span class="stringliteral">&quot;dataLoggerExample: Exiting.&quot;</span>);</div><div class="line">  <a class="code" href="classAria.html#a6abc3d39b3e9548063bb8e78375acc17">Aria::exit</a>(0);</div><div class="line">  <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.11 </li>
  </ul>
</div>
</body>
</html>
